package com.qfedu.qfoffice.controller;

import com.qfedu.qfoffice.entity.Grade;
import com.qfedu.qfoffice.entity.ResponseData;
import com.qfedu.qfoffice.entity.Student;
import com.qfedu.qfoffice.entity.User;
import com.qfedu.qfoffice.service.GradeService;
import com.qfedu.qfoffice.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @Autowired
    private GradeService gradeService;



    @RequestMapping("/selectGrade.do")
    public ResponseData<List<Grade>> selectGrade(HttpServletRequest request, Student student){
        //List<Grade> gradeList = studentService.selectGrade();
        List<Grade> gradeList = gradeService.selectGradeAll();

        ResponseData<List<Grade>> responseData = new ResponseData<>();
        responseData.setCode(0);
        responseData.setMsg("success");
        responseData.setData(gradeList);
        return responseData;
    }

   @RequestMapping("/insertStudent.do")
   public ResponseData<Student> insertStudent(HttpServletRequest request,Student student){
       User  user = (User) request.getSession().getAttribute("user");
       String uno =user.getNo();
       String name =request.getParameter("name");
       String sex =request.getParameter("sex");
       String birthday=request.getParameter("birthday");
       String cardno =request.getParameter("cardno");
       String schoolname=request.getParameter("schoolname");
       String education=request.getParameter("education");
       String phone =request.getParameter("phone");
       String email=request.getParameter("email");
       String  qq =request.getParameter("qq");
       String  gno= request.getParameter("gno");
       student.setUno(uno);
       student.setName(name);
       student.setSex(sex);
       student.setBirthday(birthday);
       student.setSchoolname(schoolname);
       student.setEducation(education);
       student.setPhone(phone);
       student.setEmail(email);
       student.setQq(qq);
       student.setGno(gno);
       ResponseData<Student> responseData = new ResponseData<>();
       int num= studentService.insertStudent(student);
       if(num>0){
           responseData.setCode(1);
       }else{
           responseData.setCode(0);
       }
       return responseData;
   }

}
